package edu.nf.project.webs.storeOperation;

import edu.nf.project.entitys.dto.storeOperation.RefundDTO;
import edu.nf.project.entitys.entity.storeOperation.convention.operate.RefundRequest;
import edu.nf.project.services.response.BaseController;
import edu.nf.project.services.response.ResultVO;
import edu.nf.project.services.storeOperation.RefundDTOService;
import edu.nf.project.services.storeOperation.RefundRequestService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author CSY
 * @date 2025 - 06 - 20
 */
@RestController
@RequestMapping("/api/refundDTO")
public class RefundDTOController extends BaseController {
    @Autowired
    private RefundDTOService refundDTOService;

    @Autowired
    private RefundRequestService refundRequestService;

    @PostMapping("/submit")
    public ResultVO<String> saveRefundDTO(@RequestParam("file") MultipartFile file,
                                          @RequestParam("refundImage") String refundImageJson){
        refundDTOService.saveRefundDTO(file, refundImageJson);
        return success();
    }

    @PostMapping("/save-refund")
    public ResultVO<Integer> saveRefund(@RequestBody RefundRequest refundRequest){
        Integer rrId = refundRequestService.insertRefundRequest(refundRequest);
        return success(rrId);
    }

        @GetMapping("/refund-detail/{rrId}")
    public ResultVO<RefundDTO> getRefundDTOByRefundId(@PathVariable Integer rrId){
        RefundDTO refundDTOByRefundId = refundDTOService.getRefundDTOByRefundId(rrId);
        return success(refundDTOByRefundId);
    }

    @GetMapping("/list")
    public ResultVO<List<RefundDTO>> listRefundDTO(){
        List<RefundDTO> refundDTOS = refundDTOService.listRefundDTO();
        return success(refundDTOS);
    }
}
